var Main = {            // Main object 
    logoIsVisible : true,
    bannerIsVisible : true
} 
 
var widgetAPI = new Common.API.Widget();    // Create Common module 
var tvKey = new Common.API.TVKeyValue(); 
 
Main.onLoad = function(){      
	if (Server.init()){
			Looper.loopFinishCallback = function(){
				_gaq.push(['_trackEvent', 'Animation', 'Loop', 'Finished']); 
				Server.fetchVideoList();
			}
			
			Server.videoDataReceivedCallback = function(){
				_gaq.push(['_trackEvent', 'Animation', 'Loop', 'Started']); 
				Looper.init();
			}
		
	 
		Server.fetchVideoList();
		
		widgetAPI.sendReadyEvent();       
		document.getElementById("anchor").focus();
	}
}	 
 
 
 Main.onUnload = function(){}
 
Main.keyDown = function(){      // Key handler 
     var keyCode = event.keyCode; 
     //alert("Main Key code : " + keyCode); 
      
     switch (keyCode) { 
          case tvKey.KEY_RETURN: 
		  case tvKey.KEY_PANEL_RETURN:
		  case tvKey.KEY_EXIT:
			widgetAPI.blockNavigation(event);
             break; 
          case tvKey.KEY_RED:
            this. toggleBanner();
            break;
          case tvKey.KEY_GREEN:
            this.toggleLogo();
            break;
     } 
}

Main.toggleBanner = function(){
	if(this.bannerIsVisible == true){
        document.getElementById("banner").style.visibility="hidden";
        this.bannerIsVisible = false;
	}else if(this.bannerIsVisible == false){
        document.getElementById("banner").style.visibility="visible";
         this.bannerIsVisible = true;
	}
}

Main.toggleLogo = function(){
	if(this.logoIsVisible == true){
        document.getElementById("logo-left").style.visibility="hidden";
        document.getElementById("logo-right").style.visibility="hidden";
        this.logoIsVisible = false;
	}else if(this.logoIsVisible == false){
        document.getElementById("logo-left").style.visibility="visible";
        document.getElementById("logo-right").style.visibility="visible";
         this.logoIsVisible = true;
	}
}